
	global option    varlabels tex plain fragment bdec(3) se starloc(1) starlevels(10 5 1) noautosumm
	global option_N    varlabels tex plain fragment bdec(3) se starloc(1) starlevels(10 5 1) summstat(N)
	global option_av varlabels tex plain fragment bdec(3)  se nocenter   nostar  noautosumm
	global option_av_N varlabels tex plain fragment bdec(3) se nocenter nostar  summstat(N)

	
	
	
cd "/Users/eliemurard/Dropbox/raw Mexcensus2010/" 

use data_replication_census2010,clear 
	
**********************************************************************************	
*	TABLE 1 
**********************************************************************************
	
	global varlist  edad male hrecipient   hh_size rural  mother_abs father_abs  gpcores 
	global num : list sizeof global(varlist)
			
	cap drop conss
	g conss=1 
	tempvar samplee
	g `samplee'= gpcores!=. 
	local j=1
	foreach y of varlist  $varlist conss    {
		outreg,clear(b`j') 
		outreg,clear(A`j') 
		nois dis "`y'"
		if "`y'" =="conss"{
		global oav ${option_av_N} 
		global odif ${option_N}  
		}
		if "`y'" !="conss"{
		global oav ${option_av} 
		global odif ${option} 
		}
		local l: variable label `y'
		cap drop x
		g x= leftbehind==1  
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Left behind")
			
		cap drop x
		g x= leftbehind==0  
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "All Untreated")
		
		cap drop x
		g x= father_abs==0 
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]    if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j') nod ${oav}   keep(x) ctitle( "", "Untreated- Coresident father")
			
		cap drop x
		g x= leftbehind==1  
		label var x  "`l'"
		qui reg  `y' x  		 [aw=factor] if (leftbehind==1 | leftbehind==0   ) & `samplee'==1  
		outreg, merge(b`j')  nod   ${odif}   keep(x) ctitle( "","(1)-(2)")
	
		cap drop x
		g x= leftbehind==1  
		label var x  "`l'"
		qui reg  `y' x  		[aw=factor] if (leftbehind==1 | father_abs==0  ) & `samplee'==1  
		outreg, merge(b`j')  nod   ${odif}   keep(x) ctitle( "", "(1)-(3)")	
			
	local j=`j'+1
	}
	local a = 1+$num
	forvalues j=1(1)`a'{
		if `j'==1 {	
		qui  outreg , store(main)  replay(b`j')  
		}
		else{
		qui outreg , store(main) append(b`j') replay(main)  
		}
		local j=`j'+1
		}
	  outreg  ,  replay(main)   title(Table 1: Descriptive statistics- children aged 0 to 16)
	

**********************************************************************************	
*	TABLE 2 
**********************************************************************************

	global varlist   gpcores   
	global num : list sizeof global(varlist)
	cap drop conss
	g conss=1 
	tempvar samplee
	g `samplee'= gpcores!=. 
	local j=1
	foreach y of varlist  $varlist conss    {
		outreg,clear(b`j') 
		nois dis "`y'"
		if "`y'" =="conss"{
		global oav ${option_av_N} 
		global odif ${option_N}  
		}
		if "`y'" !="conss"{
		global oav ${option_av} 
		global odif ${option} 
		}
		local l: variable label `y'
		cap drop x
		g x= father_abs==0 
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]    if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j') nod ${oav}   keep(x) ctitle( "", "Untreated")	
		cap drop x
		g x= father_abs==0 & mother_present==1
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]    if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j') nod ${oav}   keep(x) ctitle( "", "Coresident mother")
		cap drop x
		g x= father_abs==0   & mother_present==0
		label var x  "`l'"
		qui reg  `y'  x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Absent mother")
		cap drop x
		g x= leftbehind==1  
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Left behind")
		cap drop x
		g x= leftbehind==1    & mother_present==1
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Coresident mother")
		cap drop x
		g x= leftbehind==1    & mother_present==0
		label var x  "`l'"
		qui reg  `y'  x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Absent mother")
		cap drop x
		g x= leftbehind==1  
		label var x  "`l'"
		qui areg  `y' x    i.edad i.male rural [aw=factor] if (leftbehind==1 | father_abs==0) & `samplee'==1   , absorb(ent)  
		outreg, merge(b`j')  nod   ${odif}   keep(x) ctitle( "", "(4)-(1) w/ controls")		
		cap drop x
		g x= leftbehind==1  
		label var x  "`l'"
		qui areg  `y' x    i.edad i.male rural [aw=factor] if mother_present==1 & (leftbehind==1 | father_abs==0) & `samplee'==1   , absorb(ent)  
		outreg, merge(b`j')  nod   ${odif}   keep(x) ctitle( "", "(5)-(2) w/ controls")		
	local j=`j'+1
	}
	qui  outreg , store(main)  replay(b1)  
	qui outreg , store(main) append(b2) replay(main)  

	global varlist  gpmcores_c_mother   gpfcores_c_mother
	tempvar samplee
	g `samplee'= gpcores!=. & mother_present==1 
	local j=1
	foreach y of varlist  $varlist{
		outreg,clear(b`j') 
		nois dis "`y'"
		global oav ${option_av} 
		global odif ${option} 
		local l: variable label `y'
		cap drop x
		cap drop x
		g x= father_abs==0 
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]    if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j') nod ${oav}   keep(x) ctitle( "", "Untreated-Coresident mother")
		cap drop x
		g x= leftbehind==1   
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Left Behind-Coresident mother")
		cap drop x
		g x= leftbehind==1  
		label var x  "`l'"
		qui areg  `y' x    i.edad i.male rural [aw=factor] if mother_present==1 & (leftbehind==1 | father_abs==0) & `samplee'==1   , absorb(ent)  
		outreg, merge(b`j')  nod   ${odif}   keep(x) ctitle( "", "(5)-(2) w/ controls")		
	local j=`j'+1
	}
	qui  outreg , store(main_presmother)  replay(b1)  
	qui outreg , store(main_presmother) append(b2) replay(main_presmother)  
		
	outreg  , replace replay(main)   title(Table 2: Living arrangements of left behind and unfather_absed children)
	outreg  , replace replay(main_presmother)  title(Table 2: Living arrangements of left behind and unfather_absed children)
	
	
**********************************************************************************	
*	TABLE 3 
**********************************************************************************


	global varlist     gpmcores_c_mother  gpfcores_c_mother 
	global num : list sizeof global(varlist)
	cap drop conss
	g conss=1 
	tempvar samplee
	g `samplee'= gpcores!=. & mother_present==1 & maritalstat_cm!=. 
	local j=1
	foreach y of varlist  $varlist conss    {
		outreg,clear(b`j') 
		if "`y'" =="conss"{
		global oav ${option_av_N} 
		global odif ${option_N}  
		}
		if "`y'" !="conss"{
		global oav ${option_av} 
		global odif ${option} 
		}
		local l: variable label `y'
		cap drop x
		g x= leftbehind==1  & inlist(maritalstat_cm,1,2)
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Left behind -Partnered mother")
		cap drop x
		g x= leftbehind==0   & inlist(maritalstat_cm,1,2)
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Untreated-Partnered mother")
		cap drop x
		g x= leftbehind==1  & inlist(maritalstat_cm,3,5)
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Left behind-Non partnered mother")
		cap drop x
		g x= leftbehind==0   & inlist(maritalstat_cm,3,5)
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Untreated-Non partnered mother")	
	local j=`j'+1
	}
	local a = 1+$num
	forvalues j=1(1)`a'{
		if `j'==1 {	
		qui  outreg , store(main)  replay(b`j')  
		}
		else{
		qui outreg , store(main) append(b`j') replay(main)  
		}
		local j=`j'+1
		}	
		
	global varlist   	union	 sepasing		
	global num : list sizeof global(varlist)
	cap drop conss
	g conss=1 
	tempvar samplee
	g `samplee'= gpcores!=. & mother_present==1 & maritalstat_cm!=. 
	local j=1
	foreach y of varlist  $varlist conss    {
		outreg,clear(a`j') 	
		if "`y'" =="conss"{
		global oav ${option_av_N} 
		global odif ${option_N}  
		}
		if "`y'" !="conss"{
		global oav ${option_av} 
		global odif ${option} 
		}
		local l: variable label `y'
		cap drop x
		g x= leftbehind==1  
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(a`j')  nod ${oav}   keep(x) ctitle( "", "Left behind" )
		cap drop x
		g x= leftbehind==0  
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(a`j')  nod ${oav}   keep(x) ctitle( "", "Untreated")
		local j=`j'+1
	}
	local a = 1+$num
	forvalues j=1(1)`a'{
		if `j'==1 {	
		qui  outreg , store(B_main)  replay(a`j')  
		}
		else{
		qui outreg , store(B_main) append(a`j') replay(B_main)  
		}
		local j=`j'+1
		}
		*
		
	  outreg  , replay(main)   title(Table 3: Marital status of the mother and living arrangements of Mexican children)
	  outreg  , replay(B_main)    title(Table 3: Marital status of the mother and living arrangements of Mexican children) 
	


**********************************************************************************	
*	TABLE 6 
**********************************************************************************

	global varlist   gpcores 	
	cap drop conss
	g conss=1 
	tempvar samplee
	g `samplee'= gpcores!=. 
	local j=1
	foreach y of varlist  $varlist conss    {
		outreg,clear(b`j') 
		nois dis "`y'"
		if "`y'" =="conss"{
		global oav ${option_av_N} 
		global odif ${option_N}  
		}
		if "`y'" !="conss"{
		global oav ${option_av} 
		global odif ${option} 
		}
		local l: variable label `y'

		cap drop x
		g x= fath_mig ==1 
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]    if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j') nod ${oav}   keep(x) ctitle( "", "Enumerated migrant")
		cap drop x
		g x= fath_mig ==1  & mother_present==1
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]    if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j') nod ${oav}   keep(x) ctitle( "", "Coresident mother")
		cap drop x
		g x= fath_mig ==1   & mother_present==0
		label var x  "`l'"
		qui reg  `y'  x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Absent mother")
		
		cap drop x
		g x= leftbehind==1  
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Left Behind")
		cap drop x
		g x= leftbehind==1    & mother_present==1
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Coresident mother")
		cap drop x
		g x= leftbehind==1    & mother_present==0
		label var x  "`l'"
		qui reg  `y'  x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Absent mother")
				
	local j=`j'+1
	}
	qui  outreg , store(main)  replay(b1)  
	qui outreg , store(main) append(b2) replay(main)  
	
	global varlist  gpmcores_c_mother  gpfcores_c_mother 	
	cap drop conss
	g conss=1 
	tempvar samplee
	g `samplee'= gpcores!=. 
	local j=1
	foreach y of varlist  $varlist   {
		outreg,clear(b`j') 
	
		global oav ${option_av} 
		global odif ${option} 

		local l: variable label `y'

		cap drop x
		g x= fath_mig ==1  & mother_present==1
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]    if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Enumerated migrant- Coresident mother")

		cap drop x
		g x= leftbehind==1    & mother_present==1
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Left-behind- Coresident mother")				
	local j=`j'+1
	}
	qui  outreg , store(B_main)  replay(b1)  
	qui outreg , store(B_main) append(b2) replay(B_main)  
	
	outreg  , replay(main)  title(Table 6:Children (not co-residing with their fathers) in households with an enumerated male migrant)
	outreg  , replay(B_main)  title(Table 6: Children (not co-residing with their fathers) in households with an enumerated male migrant)
	
	
**********************************************************************************	
*	TABLE A.2, APPENDIX  
**********************************************************************************
	
	
	global varlist     gpmcores_c_mother  gpfcores_c_mother   
	global num : list sizeof global(varlist)
				
	cap drop conss
	g conss=1 
	tempvar samplee
	g `samplee'= gpcores!=. & mother_present==1 & maritalstat_cm!=. & father_abs==1 
	local j=1
	foreach y of varlist  $varlist conss    {
		outreg,clear(b`j') 
				
		nois dis "`y'"
		if "`y'" =="conss"{
		global oav ${option_av_N} 
		global odif ${option_N}  
		}
		if "`y'" !="conss"{
		global oav ${option_av} 
		global odif ${option} 
		}
		local l: variable label `y'
		cap drop x
		g x= leftbehind==1  & inlist(maritalstat_cm,1,2)
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Left Behind-Partnered mother")
		cap drop x
		g x= leftbehind==0   & inlist(maritalstat_cm,1,2)  
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Non recipient-Partnered mother")
		cap drop x
		g x= leftbehind==1   
		label var x  "`l'"
		qui reg  `y' x   i.edad  i.male i.ent i.rural    [aw=factor]     if  `samplee'==1  & inlist(maritalstat_cm,1,2)  
		outreg, merge(b`j')  nod ${odif}   keep(x) ctitle( "", "Difference")
		cap drop x
		g x= leftbehind==1  & inlist(maritalstat_cm,3,5)
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Left Behind- Non Partnered mother")
		cap drop x
		g x= leftbehind==0   & inlist(maritalstat_cm,3,5)
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(b`j')  nod ${oav}   keep(x) ctitle( "", "Non recipient-Non Partnered mother")
		cap drop x
		g x= leftbehind==1   
		label var x  "`l'"
		qui reg  `y' x   i.edad  i.male i.ent i.rural    [aw=factor]     if  `samplee'==1  & inlist(maritalstat_cm,3,5)   
		outreg, merge(b`j')  nod ${odif}   keep(x) ctitle( "", "Difference")
	local j=`j'+1
	}
	local a = 1+$num
	forvalues j=1(1)`a'{
		if `j'==1 {	
		qui  outreg , store(main)  replay(b`j')  
		}
		else{
		qui outreg , store(main) append(b`j') replay(main)  
		}
		local j=`j'+1
		}
	 
	global varlist   	union	 sepasing	 
	tempvar samplee
	g `samplee'= gpcores!=. & mother_present==1 & maritalstat_cm!=. & father_abs==1 
	local j=1
	foreach y of varlist  $varlist   {
	
		outreg,clear(a`j') 
		local l: variable label `y'
		cap drop x
		g x= leftbehind==1  
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(a`j')  nod ${option_av}     keep(x) ctitle( "", "Left Behind" )
		cap drop x
		g x= leftbehind==0  
		label var x  "`l'"
		qui reg  `y' x   [aw=factor]     if x==1 & `samplee'==1  ,nocons 
		outreg, merge(a`j')  nod ${option_av}   keep(x) ctitle( "", " Non recipient")
	local j=`j'+1
	}
	qui  outreg , store(B_main)  replay(a1)  
	qui outreg , store(B_main) append(a2) replay(B_main)  
		
		
	 outreg  , replace replay(main) ///
		title(Table A.2: Living arrangements of Mexican children not co-residing with their fathers in recipient and non-recipient households)
	 outreg  , replace replay(B_main)


	

		
	
	

	
	
	
	
